package 常用类.抽象类;

public class 模板模式 {
    public static void main(String[] args) {
        A a = new A();
        a.calculateTime();

        B b = new B();
        b.calculateTime();
    }
}
abstract class calculate{
    abstract void job();

    public void calculateTime(){
        long stat = System.currentTimeMillis();
        job();//动态绑定
        long end = System.currentTimeMillis();
        System.out.println("执行时间  " + (end - stat));
    }
}

class A extends calculate{
    long sum = 0;
    void job() {
        for (int i = 0; i < 100000; i++) {
            sum += i;
        }
    }
}

class B extends calculate{
    long sum = 0;
    void job() {
        for (int i = 0; i < 100000; i++) {
            sum *= i;
        }
    }
}
